package GUItest;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.Color;
import javax.swing.JPasswordField;

public class WindowBuilderTest extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	public static DataBaseHandler handler;
	public static ConnectionHandler connection;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					String[][] results = null;
					connection = new ConnectionHandler("cs341g3", "cs341g3", "k178552");	
					connection.establishConnection();

					handler = new DataBaseHandler(connection.getCon());

					handler.updateDateBase("USE cs341g3;");
					WindowBuilderTest frame = new WindowBuilderTest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WindowBuilderTest() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		//main_Screen mainScreen = new main_Screen();
		//mainScreen.setVisible(true);
		
		JButton btnLogIn = new JButton("Log In");
		btnLogIn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String username = textField.getText();
				String[][] result = handler.query("SELECT Password FROM Users WHERE id=" + Integer.parseInt(username) + ";", 1, 1);
				if(passwordField.getText().equals(result[0][0])){
					main_Screen mainScreen = new main_Screen();
					mainScreen.setVisible(true);
				}else{
					System.out.println("YOU SUCK AT LOGGING IN");
				}
			}
		});
		btnLogIn.setBounds(162, 197, 117, 29);
		contentPane.add(btnLogIn);
		
		textField = new JTextField();
		textField.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent arg0) {
			}
		});
		textField.setBounds(214, 86, 134, 28);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblUsername = new JLabel("Username: ");
		lblUsername.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		lblUsername.setBounds(107, 87, 108, 22);
		contentPane.add(lblUsername);
		
		JLabel lblPassword = new JLabel("Password: ");
		lblPassword.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
		lblPassword.setBounds(115, 121, 100, 28);
		contentPane.add(lblPassword);
		
		JLabel lblTigerBankBitch = new JLabel("BANK TERMINAL");
		lblTigerBankBitch.setBackground(Color.LIGHT_GRAY);
		lblTigerBankBitch.setHorizontalAlignment(SwingConstants.CENTER);
		lblTigerBankBitch.setFont(new Font("Lucida Grande", Font.PLAIN, 26));
		lblTigerBankBitch.setBounds(84, 29, 264, 29);
		contentPane.add(lblTigerBankBitch);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(214, 126, 134, 28);
		contentPane.add(passwordField);
	}
}
